<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
<%@ include file="/commons/script.jsp" %>
<script type="text/javascript" src="${ctx }/assets/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx }/assets/js/jquery.ztree.excheck.js"></script>
<link rel="stylesheet" href="${ctx }/assets/css/demo.css" type="text/css">
<link rel="stylesheet" href="${ctx }/assets/css/zTreeStyle/zTreeStyle.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<div class="widget-box widget-color-blue2">
<div class="widget-header">
	<h4 class="widget-title lighter smaller">Choose Categories</h4>
</div>
<div class="widget-body">
　　<div class="widget-main padding-8">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
</div>
</div>
<div>
<form:form action="${ctx }/sysMenu/updateMenuForRole" method="post" modelAttribute="acctRole">
<input type="hidden" name="checkedMenu" id="checkedMenu"/>
<form:hidden path="id"/>
<button id="submit-button">提交</button>
</form:form>

</div>
</body>
<script type="text/javascript">
var setting = {
		check: {
			enable: true,
			check:{
				chkboxType:{ "Y" : "ps", "N" : "ps" }
			}
		},
		data: {
			key:{
				name:"roleName"
			},
			simpleData: {
				enable: true,
				idKey:"id"
			}
		}
	};
	
jQuery(function($){
	
	$.ajax({
		url : '${ctx}/acctRole/getRoleAll',
		type : 'get',
		dataType : 'json',
		async : false,
		success : function(data){
			$.fn.zTree.init($("#treeDemo"), setting, data);
		},error : function(){
			alert("error");
		}
	});
	
	$("#submit-button").click(function(){
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
		nodes = zTree.getCheckedNodes();
		var ids = [];
		for(var i = 0;i<nodes.length;i++){
			ids[ids.length] = nodes[i].id
		}
		$("#checkedMenu").val(ids.join(","))
	})
	

});
		</script>
</html>
